package com.asf.sofom.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.asf.sofom.domain.OFiguraJuridica;

@Repository(value="figuraJuridicaDao")
public class JPAFiguraJuridica implements FiguraJuridicaDao{

	private EntityManager em = null;
	
	@PersistenceContext
	public void setEntityManager(EntityManager em){
		this.em = em;
	}	
	
	@Transactional(readOnly = true)
	@SuppressWarnings("unchecked")	
	public List<OFiguraJuridica> getFigura() {
		TypedQuery<OFiguraJuridica> tq = (TypedQuery<OFiguraJuridica>) em.createNativeQuery("Select * from figura_juridica", OFiguraJuridica.class);
		List<OFiguraJuridica> lf = tq.getResultList();		
		return lf;
	}

	public void setFigura(List<OFiguraJuridica> figura) {
		em.merge(figura);
	}

}
